package edu.netjava.ServerCharThread;

import java.net.ServerSocket;
import java.net.Socket;

public class ServerChar extends Thread {

	/**
	 * define the specified port
	 */
	int port;

	/**
	 * constructor to initial the port
	 * 
	 * @param port:the
	 *            port to bind
	 */
	public ServerChar(int port) {
		this.port = port;
	}

	/**
	 * set up the server to listen client
	 */
	public void run() {

		try {
			ServerSocket ss = new ServerSocket(port);
			System.out.println("Server is waiting at " + port + "...");

			String clientWrite = "";
			while (true) {

				Socket client = ss.accept();
				ChaterDeal cd = new ChaterDeal(client);

				new Thread(cd).start();
				
				ChaterThreadStore.add(cd);

			}

		} catch (Exception e) {

			e.printStackTrace();
		}
	}

}
